<?php
/**
 * @author Martin Pernica
 * @copyright 2009
 */

Text::h2("Úprava políčka");
echo '<br /><h3><a href="index.php?p=components&name=user&a=fields">Zpět</a></h3><br />';
$data = $db->query("SELECT * FROM {prefix}fields WHERE id = '" . intval($_GET['id']) .
    "'");
$data = $data->fetch_array();

$cats = $db->query("SELECT id,title FROM {prefix}fields_cats ORDER BY id");

while ($d = $cats->fetch_assoc()) {
	$cats_final[$d['title']] = $d['id'];
}

$form = new Form("", "post");

$form->addElement("input", array("type" => "text", "name" => "desc", "value" =>
    $data['desc'], "label" => "Popis"));

$form->addElement("input", array("type" => "text", "name" => "sql_name", "value" =>
    $data['sql_name'], "label" => "Jedinečný název", "disabled" => "disabled"));

$form->addElement("select", array("name" => "type", "label" => "Typ", "selected" =>
    $data['type']), array("Text" => "1", "Dlouhý Text" => "2"));

$form->addElement("select", array("name" => "category", "label" => "Kategorie",
    "selected" => $data['catid']), $cats_final);

$form->addElement("input", array("type" => "submit", "name" => "submit", "value" =>
    SUBMIT));

$form->render();

if ($form->isSubmitted()) {
    $query = $db->query("UPDATE {prefix}fields SET `desc` = '" . $_POST['desc'] .
        "', `type` = '" . $_POST['type'] . "', `catid` = '" . $_POST['category'] . "' WHERE id = '" . intval($_GET['id']) .
        "'");
    echo $db->error;
    if ($query) {
        $log->write(8, 'com_user', 'NOW()', 'User edited field #' . intval($_GET['id']),
            $_SESSION['id']);
        $event = 'roar.alert(\'Status\', \'Údaje byly upraveny !\');';
        array_push($Roar, $event);
    }
}

?>